package com.cicada.cocos2dsamples.samples;

import org.cocos2d.layers.CCLayer;
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCLabelAtlas;
import org.cocos2d.opengl.CCGLSurfaceView;
import org.cocos2d.types.CGPoint;
import org.cocos2d.types.CGSize;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.cicada.cocos2dsamples.log.Clog;
import com.cicada.cocos2dsamples.samples.GameBackground.Layer;

public class ImageString extends BaseActivity {

	@Override
	public CCLayer getLayer() {
		return new Layer();
	}

	class Layer extends CCLayer {

		private CCLabelAtlas labelTime;
		private CGSize winSize = CCDirector.sharedDirector().winSize();
		private int time;

		public Layer() {
			time = 90;
			labelTime = CCLabelAtlas.label(getTime(), "bar_time_number.png",
					23, 33, '0');
			labelTime.setPosition(CGPoint.ccp(winSize.getWidth() / 2,
					winSize.getHeight() / 2));
			addChild(labelTime);
			schedule("updateTime", 1.0f);
		}

		public void updateTime(float dt) {
			if (time > 0) {
				time -= 1;
			}

			labelTime.setString(getTime());
		}

		public String getTime() {
			String min = String.format("%2d", time / 60);
			String sec = String.format("%2d", time % 60);
			Clog.e("min:" + min + ", sec:" + sec);
			return min + ":" + sec;
		}
	}
}
